#!/usr/bin/env python3
"""
测试视频拆分功能的调试脚本
"""

import asyncio
import sys
from pathlib import Path

# 添加项目路径
sys.path.append(str(Path(__file__).parent))

from app.services.video_splitter import VideoSplitter
from app.utils.logger import logger

async def test_video_split():
    """测试视频拆分功能"""
    
    # 初始化拆分器
    splitter = VideoSplitter()
    
    # 使用测试视频文件
    test_video = Path("test_video.mp4")
    
    if not test_video.exists():
        logger.error(f"测试视频文件不存在: {test_video}")
        return
    logger.info(f"使用测试视频: {test_video}")
    
    try:
        # 获取视频信息
        video_info = await splitter._get_video_info(test_video)
        logger.info(f"视频信息: {video_info}")
        
        # 测试拆分
        result = await splitter.split_video_by_duration(
            video_path=test_video,
            segment_duration=60,
            max_segments=5,
            min_segment_duration=10
        )
        
        logger.info(f"拆分结果: {result}")
        
        if result.get('need_split') and result.get('segments'):
            logger.info(f"成功拆分为 {len(result['segments'])} 个片段")
            for i, segment in enumerate(result['segments']):
                logger.info(f"片段 {i}: {segment}")
        else:
            logger.warning("拆分未产生片段或不需要拆分")
            
    except Exception as e:
        logger.error(f"测试失败: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    asyncio.run(test_video_split())